package com.youpai.platform.biggod.service.convert;

import com.youpai.platform.biggod.service.entity.po.CategoryPO;
import com.youpai.platform.biggod.service.entity.po.SkillExaminePO;
import com.youpai.platform.biggod.service.entity.po.SkillPO;
import com.youpai.platform.biggod.web.entity.dto.*;
import com.youpai.platform.common.util.StringUtils;
import com.youpai.platform.user.service.entity.po.UserPO;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author huanghao
 * @version 1.0
 * @description 大神相关DTO转换
 * @date 2022/11/15
 */
public class BigGodConverter {

    //将品类po转为dto
    public static CategoryDto convertCategoryPOToCategoryDTO(final CategoryPO categoryPO){
        CategoryDto categoryDto = new CategoryDto();
        categoryDto.setCategoryId(categoryPO.getCategoryId().toString())
                    .setCategoryName(categoryPO.getCategoryName())
                    .setCategoryDesc(categoryPO.getCategoryDesc())
                    .setCategoryUnit(categoryPO.getCategoryUnit())
                    .setCategoryImg(categoryPO.getCategoryImg())
                    .setCreateTime(StringUtils.timeToString(categoryPO.getCreateTime(), StringUtils.FULL_FORMAT))
                    .setUpdateTime(StringUtils.timeToString(categoryPO.getUpdateTime(), StringUtils.FULL_FORMAT));
        return categoryDto;
    }

    //将品类po列表转为dto列表
    public static List<CategoryDto> convertCategoryPOToCategoryDTO(List<CategoryPO> categoryPOS){
        if (CollectionUtils.isEmpty(categoryPOS)) {
            return Collections.emptyList();
        }
        List<CategoryDto> categoryDtoList = new ArrayList<>(categoryPOS.size());
        for (CategoryPO categoryPO : categoryPOS) {
            categoryDtoList.add(convertCategoryPOToCategoryDTO(categoryPO));
        }
        return categoryDtoList;
    }

    //将技能po转为dto
    public static SkillExamineDto convertSkillExaminePOToSkillExamineDTO(
            final SkillExaminePO skillExaminePO,
            final UserPO userPO, final String accId){
        SkillExamineDto skillExamineDto = new SkillExamineDto();
        skillExamineDto.setExamineId(String.valueOf(skillExaminePO.getSkillExamineId()))
                .setUid(String.valueOf(skillExaminePO.getGodUid()))
                .setAccId(accId)
                .setNickName(userPO.getNickName())
                .setEmail(userPO.getEmail())
                .setSkill(skillExaminePO.getSkill())
                .setRank(skillExaminePO.getRank())
                .setPosition(skillExaminePO.getPosition())
                .setStyle(skillExaminePO.getStyle())
                .setPrice(skillExaminePO.getUnitPrice())
                .setScreenshot(skillExaminePO.getScreenshot())
                .setExamineStatus(skillExaminePO.getExamineStatus())
                .setCreateTime(skillExaminePO.getCreateTime().getTime())
                .setUpdateTime(skillExaminePO.getUpdateTime().getTime());
        return skillExamineDto;
    }

    //将技能po列表转为dto列表
    public static List<SkillExamineDto> convertSkillExaminePOToSkillExamineDTO(
            List<SkillExaminePO> skillExaminePOS,
            Map<Long, UserPO> userPOMap,
            Map<String, String> userFollowPOMap){
        if (CollectionUtils.isEmpty(skillExaminePOS)) {
            return Collections.emptyList();
        }
        List<SkillExamineDto> skillExamineDtoList = new ArrayList<>(skillExaminePOS.size());
        for (SkillExaminePO skillExaminePO : skillExaminePOS) {
            skillExamineDtoList.add(
                    convertSkillExaminePOToSkillExamineDTO(
                            skillExaminePO, userPOMap.get(skillExaminePO.getGodUid()), userFollowPOMap.get(String.valueOf(skillExaminePO.getGodUid()))));
        }
        return skillExamineDtoList;
    }

    //将用户po转为大神dto
    public static BigGodListDto convertUserPOToBigGodListDto(final UserPO userPO){
        BigGodListDto bigGodListDto = new BigGodListDto();
        bigGodListDto.setUid(String.valueOf(userPO.getUid()))
                .setUserName(userPO.getUserName())
                .setNickName(userPO.getNickName())
                .setAvatar(userPO.getAvatar())
                .setSummary(userPO.getSummary());
        return bigGodListDto;
    }

    //将用户pos转为大神dtos
    public static List<BigGodListDto> convertUserPOToBigGodListDto(final List<UserPO> userPOS){
        if (CollectionUtils.isEmpty(userPOS)) {
            return Collections.emptyList();
        }
        List<BigGodListDto> bigGodListDtos = new ArrayList<>(userPOS.size());
        for (UserPO userPO : userPOS) {
            bigGodListDtos.add(convertUserPOToBigGodListDto(userPO));
        }
        return bigGodListDtos;
    }

    //将技能po转为技能dto
    public static SkillDto convertSkillPOToSkillDto(final SkillPO skillPO){
        SkillDto SkillDto = new SkillDto();
        SkillDto.setSkillId(String.valueOf(skillPO.getSkillId()))
                .setSkill(skillPO.getSkill())
                .setRank(skillPO.getRank())
                .setPosition(skillPO.getPosition())
                .setStyle(skillPO.getStyle())
                .setUnitPrice(String.valueOf(skillPO.getUnitPrice()))
                .setScreenshot(skillPO.getScreenshot());
        return SkillDto;
    }

    //将技能pos转为技能dtos
    public static List<SkillDto> convertSkillPOToSkillDto(final List<SkillPO> skillPOS){
        if (CollectionUtils.isEmpty(skillPOS)) {
            return Collections.emptyList();
        }
        List<SkillDto> skillDtoList = new ArrayList<>(skillPOS.size());
        for (SkillPO skillPO : skillPOS) {
            skillDtoList.add(convertSkillPOToSkillDto(skillPO));
        }
        return skillDtoList;
    }

    public static BigGodDto convertUserPOAndSkillPOToBigGodDto(UserPO userPO, List<SkillPO> skillPOS) {
        BigGodDto BigGodDto = new BigGodDto();
        BigGodDto.setUid(String.valueOf(userPO.getUid()))
                .setUserName(userPO.getUserName())
                .setNickName(userPO.getNickName())
                .setAvatar(userPO.getAvatar())
                .setSummary(userPO.getSummary())
                .setSkillDtoList(convertSkillPOToSkillDto(skillPOS));
        return BigGodDto;
    }
}
